<?php

/**
 * User filter form base class.
 *
 * @package    ProdAssistant
 * @subpackage filter
 * @author     Paweł Świtalla
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 29570 2010-05-21 14:49:47Z Kris.Wallsmith $
 */
abstract class BaseUserFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'firstName'     => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'lastName'      => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'number'        => new sfWidgetFormFilterInput(),
      'mobile'        => new sfWidgetFormFilterInput(),
      'lastLogon'     => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())),
      'login'         => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'password'      => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'salt'          => new sfWidgetFormFilterInput(),
      'email'         => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'role_id'       => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Role'), 'add_empty' => true)),
      'position'      => new sfWidgetFormFilterInput(),
      'directory'     => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'created_at'    => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'updated_at'    => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'settings_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Settings')),
    ));

    $this->setValidators(array(
      'firstName'     => new sfValidatorPass(array('required' => false)),
      'lastName'      => new sfValidatorPass(array('required' => false)),
      'number'        => new sfValidatorPass(array('required' => false)),
      'mobile'        => new sfValidatorPass(array('required' => false)),
      'lastLogon'     => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'login'         => new sfValidatorPass(array('required' => false)),
      'password'      => new sfValidatorPass(array('required' => false)),
      'salt'          => new sfValidatorPass(array('required' => false)),
      'email'         => new sfValidatorPass(array('required' => false)),
      'role_id'       => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Role'), 'column' => 'id')),
      'position'      => new sfValidatorPass(array('required' => false)),
      'directory'     => new sfValidatorPass(array('required' => false)),
      'created_at'    => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'updated_at'    => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'settings_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Settings', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('user_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function addSettingsListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.UserSettings UserSettings')
      ->andWhereIn('UserSettings.setting_id', $values)
    ;
  }

  public function getModelName()
  {
    return 'User';
  }

  public function getFields()
  {
    return array(
      'id'            => 'Number',
      'firstName'     => 'Text',
      'lastName'      => 'Text',
      'number'        => 'Text',
      'mobile'        => 'Text',
      'lastLogon'     => 'Date',
      'login'         => 'Text',
      'password'      => 'Text',
      'salt'          => 'Text',
      'email'         => 'Text',
      'role_id'       => 'ForeignKey',
      'position'      => 'Text',
      'directory'     => 'Text',
      'created_at'    => 'Date',
      'updated_at'    => 'Date',
      'settings_list' => 'ManyKey',
    );
  }
}
